<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/Par-Ideal/PROJETO/src/util/Conexao.php';

class ComboBox{
	
	public static function PopulaComboBox($tabela, $value, $descricao, $condicao, $selecionado){
		$conexao = Conexao::Conecta();
		
		if($condicao!=null || $condicao!=''){
			$sql = "select ".$value." , ".$descricao." from ".$tabela." where ". $condicao ." order by ".$descricao;
		}else{
			$sql = "select ".$value." , ".$descricao." from ".$tabela." order by ".$descricao;
		}
		
		
		$consulta = $conexao->query($sql);	
		
		echo " <option  value='**'>Selecione</option>";	
		
		while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
			$selected = "";	
			if($selecionado == $linha[$value])
				$selected = "selected";			
			echo " <option ".$selected." value=".$linha[$value].">".$linha[$descricao]."</option>";	       
	    }
		$conexao=null;
	}	
	
	/**
	public static function PopulaComboBoxAJAX($tabela, $value, $descricao, $condicao){
		$conexao = Conexao::Conecta();
		
		if($condicao!=null || $condicao!=''){
			$sql = "select ".$value." , ".$descricao." from ".$tabela." where ". $condicao ." order by ".$descricao;
		}else{
			$sql = "select ".$value." , ".$descricao." from ".$tabela." order by ".$descricao;
		}
		
		
		
		$consulta = $conexao->query($sql);	
		//echo " <option value='*****'>Selecione</option>";	 
		$dados = array();
		while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {			
			$dados['option'][] = array(
                                'value'  => $linha[$value],
                                'text' => $linha[$descricao]
                            );				       
	    }
		$conexao=null;
		
		echo json_encode($dados);
	}	
	**/
}
?>